package com.easy.dfcapi.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.core.web.Api20Controller;
import com.easy.dfcapi.res.Response;
import com.easy.dfcapi.res.SellerUserRes;
import com.easy.dfcapi.service.ApiSellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 活动相关控制器
 */

@Controller
@RequestMapping(value = "${apiPath}/2.0/seller")
public class ApiSellerController extends Api20Controller {


    @Autowired
    private ApiSellerService sellerService;


    /**
     * 厂家版首页
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HomePage")
    public Result HomePage(Model model) {
        try {
            return sellerService.HomePage();
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 获取厂品类型
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getCateories", method = RequestMethod.POST)
    public Result Cateories(Response<SellerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }

            return sellerService.Cateories(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 获取厂品列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "Products", method = RequestMethod.POST)
    public Result Products(Response<SellerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }

            return sellerService.Products(response);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }


}
